﻿#include "Graphics52ValveItem.h"
#include <QBrush>
#include <QPen>
#include <QPainter>
#include <QDebug>


Graphics52ValveItem::Graphics52ValveItem()
    : GraphicsAirValveItem()
{
    m_keyPoints[0] = QPoint(-25, -35);
    m_keyPoints[1] = QPoint(25, -35);
    m_keyPoints[2] = QPoint(-25, 35);
    m_keyPoints[3] = QPoint(25, 35);
}

QPointF Graphics52ValveItem::keyPoint(int i)
{
    return m_keyPoints[i];
}

QRectF Graphics52ValveItem::boundingRect() const
{
    return QRectF(-25, -20 - 17, 50, 34 + 40);
}

void Graphics52ValveItem::setEnable(bool enable)
{
    m_enable = enable;
    update();
}

void Graphics52ValveItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    QPen penOn(Qt::black), penOff(Qt::red);
    penOn.setWidth(3);
    penOff.setWidth(3);

    if(m_enable)
    {
        painter->save();
        painter->translate(0, -20);
        drawStateOn(painter, Right);

        painter->translate(0, 40);
        drawStateOff(painter, Right);

        // painter->translate(0, 70);
        // drawStateOff(painter, Right);

        painter->restore();
    }
    else
    {
        painter->save();
        painter->translate(0, -20);
        drawStateOff(painter, Right);

        painter->translate(0, 40);
        drawStateOn(painter, Right);

        // painter->translate(0, 70);
        // drawStateOn(painter, Right);
        painter->restore();
    }
    painter->setPen(penOn);
    painter->drawLine(QLine(-25, -20, -25, 20));
    // painter->drawLine(QLine(25, 0, 25, 35));
}
